package com.cmower.interview.questions;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author 沉默王二，一枚有趣的程序员
 */
public class HashMapVsTreeMap {
    public static void main(String[] args) {
Map<String,String> hashMap = new HashMap<>();
hashMap.put("cmower", "沉默王二");
hashMap.put("cmowsan", "沉默王三");
hashMap.put("cmowsi", "沉默王四");
hashMap.put("cmowu", "沉默王五");
hashMap.put("cmowliu", "沉默王六");

Iterator<String> hashIterator = hashMap.keySet().iterator();
while(hashIterator.hasNext()){
    String key = hashIterator.next();
    System.out.println(hashMap.get(key) + " " + key);
}

        System.out.println();

Map<String,String> treeMap = new TreeMap<>();
treeMap.put("cmower", "沉默王二");
treeMap.put("cmowsan", "沉默王三");
treeMap.put("cmowsi", "沉默王四");
treeMap.put("cmowu", "沉默王五");
treeMap.put("cmowliu", "沉默王六");

Iterator<String> treeIterator = treeMap.keySet().iterator();
while(treeIterator.hasNext()){
    String key = treeIterator.next();
    System.out.println(treeMap.get(key) + " " + key);
}
    }
}
